<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title> 

</head>
<jsp:include page="../default.jsp" />
<body>
    <div style="padding-bottom: 5px; padding-top: 5px;">
		<fieldset id="query">
			<legend>
				<span style="font-weight: bold;">查询条件</span>
			</legend>
			<div id="form" class="fieldset-body">
				<table width="100%" cellspacing="0" cellpadding="0" border="0">
					<tr height="34">
			     		<td align="right"><span>标题：</span></td>
						<td width="150px;"><input name="title" class="mini-textbox"/></td> 
						<td align="right"><span>类型：</span></td>
						<td width="150px;"><input name="type" class="mini-combobox" url="${pageContext.request.contextPath}/base/dic/getSingleDic.do?dicType=type"
							valueField="code" textField="codeValue" showNullItem="true"/></td>
						<td align="right"><span>时间：</span></td>
						<td width="150px;"><input name="time" class="mini-datepicker" format="yyyy-MM-dd"/></td>
						<td align="right"></td>
						<td align="left"><a class="mini-button" value="查询" iconCls="icon-search" 
							onclick="query()">查询</a>&nbsp;&nbsp;<a class="mini-button"
							value="重置" iconCls="icon-reload" onclick="CommonUtil.prototype.reset()">重置</a></td>
					</tr>
				</table>
			</div>
		</fieldset>
    </div>
    <div class="mini-toolbar" style="border-bottom: 0;">
		<a class="mini-button" iconCls="icon-add" onclick="toForm('add')">新增</a>
		<a class="mini-button" iconCls="icon-edit" onclick="toForm('edit')">修改</a>
		<a class="mini-button" iconCls="icon-node" onclick="toForm('view')">查看</a>
		<a class="mini-button" iconCls="icon-remove" onclick="toRemove()">删除</a>
	</div>
    <div class="mini-fit">
    	<div id="datagrid" class="mini-datagrid" style="width: 100%; height: 100%;"
       	 url="${pageContext.request.contextPath}/demo/query.do" idField="id" 
       	 multiSelect="true" allowUnselect="true" allowAlternating="true" onload="PageHelper.prototype.commonError">
            <div property="columns">
            	<div type="checkcolumn"></div>
            	<div field="id" width="100" headerAlign="center">编号</div>
            	<div field="title" width="170" headerAlign="center">标题 </div>  
            	<div field="type" width="40" headerAlign="center" dicCode renderer="DicManager.prototype.dicRender">类型</div>  
            	<div field="time" width="100" headerAlign="center" dateFormat="yyyy-MM-dd HH:mm:ss">时间 </div>                           
        	</div>
       	</div> 
    </div>
    <script type="text/javascript">   
    	new PageHelper().init();
    	mini.parse();
    	var grid = mini.get("datagrid");
		grid.load();
		var form = new mini.Form("#form");
		   
    	function query(){
			grid.load(form.getData(true));
    	}
    	
    	function toForm(action){
    		if(action == "edit" || action == "view"){
    			var row = CommonUtil.prototype.getSelectRow();
    			if(!row){
    				return;
    			}	
    		}   		
    		mini.open({
    			url: "${pageContext.request.contextPath}/demo/toForm.do",
    			title: "示例", 
    			width: 600, 
    			height: 400,
    			allowResize : false,
   				onload: function () {
        			var iframe = this.getIFrameEl();
        			var data = {action: action};
        			if(row){
        				data["id"] = row.id;
        			}
        			iframe.contentWindow.setData(data);
    			},
    			ondestroy: function (action) {
        			grid.reload();
        			grid.clearSelect();
    			}
			});
    	}
    	
    	function toRemove(){
    		var keys = CommonUtil.prototype.getSelectKeys(null, "id");
    		if(keys){
    			CommonUtil.prototype.mask();
    			$.ajax({
                    url: "${pageContext.request.contextPath}/demo/remove.do",
                    data : {keys: keys},
                    type : "POST",
					dataType : "json",
                    success: function (data, textStatus, jqXHR) {
                    	CommonUtil.prototype.unmask();
                    	if(data.success){
                    		mini.alert("删除成功", "提醒", function(){
								grid.reload();
        						grid.clearSelect();
							});
                    	}                       
                    }
                });
    		}
    	}
	</script>
  </body>
</html>
